package route;

import static org.junit.Assert.*;
import junit.framework.TestCase;

import org.junit.Test;

public class RouteTest extends TestCase {

	public void testConstructor() {
		ALoDistance r1 = new MTDistance();
		ALoDistance r2 = new ConsDistance(new Segment(new Station("suoi tien",
				new Location(2, "xa lo ha noi")), 50.0), r1);
		ALoDistance r3 = new ConsDistance(new Segment(new Station(
				"dai hoc nong lam", new Location(1, "quoc lo 1A")), 70.0), r2);
		ALoDistance r4 = new ConsDistance(new Segment(new Station("nguyen xi",
				new Location(4, "nguyen xi")), 30.0), r3);
		ALoDistance r5 = new ConsDistance(new Segment(new Station("ben thanh",
				new Location(23 / 9, "duong 23/9")), 25.0), r4);
		Route ro1 = new Route("xe buyt so 19", r5);

		ALoDistance d1 = new ConsDistance(new Segment(new Station(
				"dai hoc quoc gia", new Location(1, "quoc lo 1A")), 45.0), r1);
		ALoDistance d2 = new ConsDistance(new Segment(new Station("spkt",
				new Location(23, "vo van ngan")), 10.0), d1);
		ALoDistance d3 = new ConsDistance(new Segment(new Station(
				"cho thu duc", new Location(34, "vo van ngan")), 15.0), d2);
		ALoDistance d4 = new ConsDistance(new Segment(new Station(
				"cho ba trieu", new Location(8, "ba trieu")), 30.0), d3);
		ALoDistance d5 = new ConsDistance(new Segment(new Station(
				"ben xe quan 8", new Location(34, "quan 8")), 50.0), d4);
		Route ro2 = new Route("xe buyt so 8", d5);

		System.out.println(ro1);
		System.out.println(ro2);
	}

	public void testPassAcross() {
		ALoDistance r1 = new MTDistance();
		ALoDistance r2 = new ConsDistance(new Segment(new Station("suoi tien",
				new Location(2, "xa lo ha noi")), 50.0), r1);
		ALoDistance r3 = new ConsDistance(new Segment(new Station(
				"dai hoc nong lam", new Location(1, "quoc lo 1A")), 70.0), r2);
		ALoDistance r4 = new ConsDistance(new Segment(new Station("nguyen xi",
				new Location(4, "nguyen xi")), 30.0), r3);
		ALoDistance r5 = new ConsDistance(new Segment(new Station("ben thanh",
				new Location(23 / 9, "duong 23/9")), 25.0), r4);
		Route ro1 = new Route("xe buyt so 19", r5);

		ALoDistance d1 = new ConsDistance(new Segment(new Station(
				"dai hoc quoc gia", new Location(1, "quoc lo 1A")), 45.0), r1);
		ALoDistance d2 = new ConsDistance(new Segment(new Station("spkt",
				new Location(23, "vo van ngan")), 10.0), d1);
		ALoDistance d3 = new ConsDistance(new Segment(new Station(
				"cho thu duc", new Location(34, "vo van ngan")), 15.0), d2);
		ALoDistance d4 = new ConsDistance(new Segment(new Station(
				"cho ba trieu", new Location(8, "ba trieu")), 30.0), d3);
		ALoDistance d5 = new ConsDistance(new Segment(new Station(
				"ben xe quan 8", new Location(34, "quan 8")), 50.0), d4);
		Route ro2 = new Route("xe buyt so 8", d5);

		assertTrue(r2.passAcross("xa lo ha noi"));
		assertTrue(r3.passAcross("quoc lo 1A"));
		assertTrue(r4.passAcross("nguyen xi"));
		assertTrue(r5.passAcross("duong 23/9"));
		assertTrue(d1.passAcross("quoc lo 1A"));
		assertTrue(d2.passAcross("vo van ngan"));
		assertTrue(d3.passAcross("vo van ngan"));
		assertTrue(d4.passAcross("ba trieu"));
		assertTrue(d5.passAcross("quan 8"));
	}

	public void testHowlong() {
		ALoDistance r1 = new MTDistance();
		ALoDistance r2 = new ConsDistance(new Segment(new Station("suoi tien",
				new Location(2, "xa lo ha noi")), 50.0), r1);
		ALoDistance r3 = new ConsDistance(new Segment(new Station(
				"dai hoc nong lam", new Location(1, "quoc lo 1A")), 70.0), r2);
		ALoDistance r4 = new ConsDistance(new Segment(new Station("nguyen xi",
				new Location(4, "nguyen xi")), 30.0), r3);
		ALoDistance r5 = new ConsDistance(new Segment(new Station("ben thanh",
				new Location(23 / 9, "duong 23/9")), 25.0), r4);
		Route ro1 = new Route("xe buyt so 19", r5);

		ALoDistance d1 = new ConsDistance(new Segment(new Station(
				"dai hoc quoc gia", new Location(1, "quoc lo 1A")), 45.0), r1);
		ALoDistance d2 = new ConsDistance(new Segment(new Station("spkt",
				new Location(23, "vo van ngan")), 10.0), d1);
		ALoDistance d3 = new ConsDistance(new Segment(new Station(
				"cho thu duc", new Location(34, "vo van ngan")), 15.0), d2);
		ALoDistance d4 = new ConsDistance(new Segment(new Station(
				"cho ba trieu", new Location(8, "ba trieu")), 30.0), d3);
		ALoDistance d5 = new ConsDistance(new Segment(new Station(
				"ben xe quan 8", new Location(34, "quan 8")), 50.0), d4);
		Route ro2 = new Route("xe buyt so 8", d5);

		assertEquals(r2.howlong(), 50.0);
		assertEquals(r3.howlong(), 120.0);
		assertEquals(r4.howlong(), 150.0);
		assertEquals(r5.howlong(), 175.0);
		assertEquals(d1.howlong(), 45.0);
		assertEquals(d2.howlong(), 55.0);
		assertEquals(d3.howlong(), 70.0);
		assertEquals(d4.howlong(),100.0 );
		assertEquals(d5.howlong(), 150.0);
	}
}
